package com.jinke.api.modules.app.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;

@Configuration
@EnableAsync
public class AsyncConfig {

    @Bean(name = "ezeeShipThreadPool")
    public Executor ezeeShipThreadPool() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        // 设置核心线程数
        //executor.setCorePoolSize(5);
        executor.setCorePoolSize(10);
        // 设置最大线程数
        //executor.setMaxPoolSize(20);
        executor.setMaxPoolSize(25);
        // 设置队列容量
        //executor.setQueueCapacity(25);
        executor.setQueueCapacity(100);
        // 设置线程名前缀
        executor.setThreadNamePrefix("CustomThread-");
        executor.initialize();
        return executor;
    }
    @Bean(name = "createOrderThreadPool")
    public Executor createOrderThreadPool() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        // 设置核心线程数
        executor.setCorePoolSize(5);
        // 设置最大线程数
        executor.setMaxPoolSize(20);
        // 设置队列容量
        executor.setQueueCapacity(30);
        // 设置线程名前缀
        executor.setThreadNamePrefix("createOrderThread-");
        executor.initialize();
        return executor;
    }
}